#!/usr/bin/env python
import socket
import os
import urllib2

INTEL_PROXY = {'http' : 'http://proxy01.pd.intel.com:911'}

def hostname():
    hostname = socket.gethostname()
    if not hostname: hostname = os.environ.get('HOSTNAME', '')
    return hostname

# Get working proxy settings based on current network situation
def getproxy():
    proxy = {}
    for ipaddr in socket.gethostbyname_ex(socket.gethostname())[2]:
        if ipaddr[:6] == "10.239":
            proxy = INTEL_PROXY
    return proxy

user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.1; it; rv:1.8.1.11) Gecko/20071127 Firefox/2.0.0.11'
headers = { 'User-Agent' : user_agent }

def myurlopen(url, data=None, proxies=None):
    proxy_support = urllib2.ProxyHandler(getproxy())
    opener = urllib2.build_opener(proxy_support)

    req = urllib2.Request(url, data, headers)

    return opener.open(req)
